package p2p.logic.connection.communication;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import p2p.logic.connection.ConnectionOwner;
import p2p.logic.connection.communication.message.Message;
/**
 * 
 * AbstractCommunicationHandler is responsible handling incoming
 * and outgoing messages. 

 */
public abstract class AbstractCommunicationHandler {

	protected Map<UUID, Set<Message>> messageReceivedMap;
	protected Map<UUID, Set<Message>> messageSendMap;
	protected Set<UUID> ackMessages;
	protected Set<UUID> broadCastMessages;
	
	protected ConnectionOwner owner;
	
	public AbstractCommunicationHandler(ConnectionOwner owner) {
	
		this.owner = owner;
		this.messageReceivedMap = new HashMap<UUID, Set<Message>>();
		this.messageSendMap = new HashMap<UUID, Set<Message>>();
		this.ackMessages = new HashSet<UUID>();
		this.broadCastMessages = new HashSet<UUID>();
	}

	public abstract void handleReceived(byte[] recieved);
	
	public abstract void handleReceivedMessage(Message message);
	
	public abstract void handleSended(byte[] send);
	
	public abstract void handleSendedMessage(Message send);

	public abstract void processReceivedMessage(Message message);
	
	public abstract void processSendMessage(Message message);

	public boolean hasAlreadySendBroadCast(UUID message){
		if (this.broadCastMessages.contains(message))
			return true;
		else
			return false;
	}
}
